package com.fastwire.carriere.inventory.entity;

import java.util.List;
import java.util.Set;

import org.tmforum.mtop.fmw.xsd.nam.v1.NamingAttributeListType;
import org.tmforum.mtop.fmw.xsd.nam.v1.NamingAttributeType;
import org.tmforum.mtop.fmw.xsd.nam.v1.RelativeDistinguishNameType;
import org.tmforum.mtop.nrf.xsd.cc.v1.CrossConnectType.AEndRefList;
import org.tmforum.mtop.nrf.xsd.cc.v1.CrossConnectType.ZEndRefList;
import org.tmforum.mtop.nrf.xsd.tpdata.v1.TerminationPointDataListType;
import org.tmforum.mtop.nrf.xsd.tpdata.v1.TerminationPointDataType;

import com.fastwire.carriere.common.entity.BaseObject;
import com.fastwire.carriere.common.util.EntityUtil;

// TODO: Auto-generated Javadoc
/**
 * The Class SubTerminationPoint.
 */
public class SubTerminationPoint extends BaseObject {

	/** The oid. */
	private long oid;

	/** The version. */
	private int version;

	/** The name. */
	private String name;

	/** The type. */
	private String type;

	/** The trans parameters. */
	private Set<TransmissionParameter> transParameters;

	/** The ip address. */
	private TPIPAddress ipAddress;

	/** The ingress tmd ref. */
	private String ingressTmdRef;

	/** The egress tmd ref. */
	private String egressTmdRef;

	/**
	 * Instantiates a new sub termination point.
	 */
	public SubTerminationPoint() {
		super();

	}

	/**
	 * Instantiates a new sub termination point.
	 * 
	 * @param terminationPointDataListType
	 *            the termination point data list type
	 */
	public SubTerminationPoint(
			TerminationPointDataListType terminationPointDataListType) {

		if (terminationPointDataListType != null
				&& !terminationPointDataListType.getTpData().isEmpty()) {
			TerminationPointDataType terminationPointDataType = terminationPointDataListType
					.getTpData().get(0);

			List<RelativeDistinguishNameType> rdnList = terminationPointDataType
					.getTpRef().getRdn();

			setName(EntityUtil.convertRtnListToString(rdnList));
			setType(rdnList.get(rdnList.size() - 1).getType());
			if (terminationPointDataType.getIngressTmdRef() != null)
				setIngressTmdRef(EntityUtil
						.convertRtnListToString(terminationPointDataType
								.getIngressTmdRef().getRdn()));
			if (terminationPointDataType.getEgressTmdRef() != null)
				setEgressTmdRef(EntityUtil
						.convertRtnListToString(terminationPointDataType
								.getEgressTmdRef().getRdn()));

			if (terminationPointDataType.getTransmissionParametersList() != null) {

				setTransParameters(EntityUtil
						.convertLayeredTransParameters(terminationPointDataType
								.getTransmissionParametersList()));

			}

			if (terminationPointDataType.getIpAddressList() != null) {

			}

		}

	}

	/**
	 * Instantiates a new sub termination point.
	 * 
	 * @param namingAttributeListType
	 *            the naming attribute list type
	 */
	public SubTerminationPoint(NamingAttributeListType namingAttributeListType) {

		if (namingAttributeListType != null) {
			List<NamingAttributeType> aendNamingAttributeTypes = namingAttributeListType
					.getName();

			configureTpName(aendNamingAttributeTypes);

		}

	}

	/**
	 * Instantiates a new sub termination point.
	 * 
	 * @param zEndRefList
	 *            the z end ref list
	 */
	public SubTerminationPoint(ZEndRefList zEndRefList) {

		if (zEndRefList != null) {
			List<NamingAttributeType> aendNamingAttributeTypes = zEndRefList
					.getZEndName();

			configureTpName(aendNamingAttributeTypes);

		}

	}

	/**
	 * Instantiates a new sub termination point.
	 * 
	 * @param aEndRefList
	 *            the a end ref list
	 */
	public SubTerminationPoint(AEndRefList aEndRefList) {

		if (aEndRefList != null) {
			List<NamingAttributeType> aendNamingAttributeTypes = aEndRefList
					.getAEndName();

			configureTpName(aendNamingAttributeTypes);

		}

	}

	/**
	 * Gets the version.
	 * 
	 * @return the version
	 */
	public int getVersion() {
		return version;
	}

	/**
	 * Sets the version.
	 * 
	 * @param version
	 *            the new version
	 */
	public void setVersion(int version) {
		this.version = version;
	}

	/**
	 * Sets the ip address.
	 * 
	 * @param ipAddress
	 *            the new ip address
	 */
	public void setIpAddress(TPIPAddress ipAddress) {
		this.ipAddress = ipAddress;
	}

	/**
	 * Gets the ip address.
	 * 
	 * @return the ip address
	 */
	public TPIPAddress getIpAddress() {
		return ipAddress;
	}

	/**
	 * Gets the oid.
	 * 
	 * @return the oid
	 */
	public long getOid() {
		return oid;
	}

	/**
	 * Sets the oid.
	 * 
	 * @param oid
	 *            the new oid
	 */
	public void setOid(long oid) {
		this.oid = oid;
	}

	/**
	 * Sets the name.
	 * 
	 * @param name
	 *            the new name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Gets the name.
	 * 
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * Gets the trans parameters.
	 * 
	 * @return the trans parameters
	 */
	public Set<TransmissionParameter> getTransParameters() {
		return transParameters;
	}

	/**
	 * Sets the trans parameters.
	 * 
	 * @param transParameters
	 *            the new trans parameters
	 */
	public void setTransParameters(Set<TransmissionParameter> transParameters) {
		this.transParameters = transParameters;
	}

	/**
	 * Configure tp name.
	 * 
	 * @param namingAttributeTypes
	 *            the naming attribute types
	 */
	public void configureTpName(List<NamingAttributeType> namingAttributeTypes) {

		if (namingAttributeTypes.size() > 0) {

			List<RelativeDistinguishNameType> rdnList = namingAttributeTypes
					.get(0).getRdn();

			setName(EntityUtil.convertRtnListToString(rdnList));

			setType(rdnList.get(rdnList.size() - 1).getType());
		}

	}

	/**
	 * Gets the ingress tmd ref.
	 * 
	 * @return the ingress tmd ref
	 */
	public String getIngressTmdRef() {
		return ingressTmdRef;
	}

	/**
	 * Sets the ingress tmd ref.
	 * 
	 * @param ingressTmdRef
	 *            the new ingress tmd ref
	 */
	public void setIngressTmdRef(String ingressTmdRef) {
		this.ingressTmdRef = ingressTmdRef;
	}

	/**
	 * Gets the egress tmd ref.
	 * 
	 * @return the egress tmd ref
	 */
	public String getEgressTmdRef() {
		return egressTmdRef;
	}

	/**
	 * Sets the egress tmd ref.
	 * 
	 * @param egressTmdRef
	 *            the new egress tmd ref
	 */
	public void setEgressTmdRef(String egressTmdRef) {
		this.egressTmdRef = egressTmdRef;
	}

	/**
	 * Gets the type.
	 * 
	 * @return the type
	 */
	public String getType() {
		return type;
	}

	/**
	 * Sets the type.
	 * 
	 * @param type
	 *            the new type
	 */
	public void setType(String type) {
		this.type = type;
	}

}
